import uuid
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.conf import settings


class UserProfile(AbstractUser):
    uid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    avatar_url = models.URLField(max_length=255, blank=True, verbose_name="头像链接")
    nickname = models.CharField(max_length=16, verbose_name="昵称")
    # friends = models.ManyToManyField(to='Friends')

    REQUIRED_FIELDS = ['nickname']
    USERNAME_FIELD = 'username'

    class Meta:
        db_table = 'user'
        verbose_name = "用户账号"
        verbose_name_plural = "用户账号"

    @property
    def avatar(self):
        if not self.avatar_url:
            return settings.AVATAR_URL_PREFIX + settings.DEFAULT_AVATAR
        return self.avatar_url

    def __str__(self):
        return self.nickname






